import { mongo } from "../mogoConfig"

// 复合索引
const run = async () => {
    const tb = mongo.db("my_test").collection("students")

    await tb.dropIndexes()

    let result = await tb.createIndex({ name: 1, gpa: -1 }, { name: "idx1" })
    console.log(JSON.stringify(result))

    let cursor = await tb.find({ name: "Alice", gpa: 3.6 })
    console.log("查询结果1---------------------------")
    for await (const item of cursor) {
        console.log(JSON.stringify(item))
    }

    cursor = await tb.find({ name: "Bob" })
    console.log("查询结果2---------------------------")
    for await (const item of cursor) {
        console.log(JSON.stringify(item))
    }

}


run()
    .catch((error) => {
        console.log(error)
    })
    .finally(() => {
        mongo.close()
        console.log("执行结束")
    })